package resp

import (
	"a-common/constant"
	"a-common/domain/ctx"

	"github.com/gofiber/fiber/v2"
)

type MyResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg,omitempty"`
	Data any    `json:"data,omitempty"`
}

func Ok(c *fiber.Ctx) error {
	resp := &MyResp{
		Code: 0,
		Msg:  "success",
	}
	return c.JSON(resp)
}

func Resp(c *fiber.Ctx, data any) error {
	resp := &MyResp{
		Code: 0,
		Msg:  "success",
		Data: data,
	}
	return c.JSON(resp)
}

// 获取登入用户信息
func GetUser(c *fiber.Ctx) ctx.UserCtx {
	defer func() {
		recover()
	}()
	return c.UserContext().Value(ctx.UserCtxKey).(ctx.UserCtx)
}

func GetDeviceType(device string) (t int) {
	if device == constant.PC {
		t = 1
	} else if device == constant.APP {
		t = 2
	} else if device == constant.XCX {
		t = 3
	} else {
		t = 0
	}
	return t

}
